package com.ethanzzh.ethanzzh_xdclass.dto;


import com.ethanzzh.ethanzzh_xdclass.exception.ZzhException;
import com.ethanzzh.ethanzzh_xdclass.utils.SimpleResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 异常处理控制器
 */
@ControllerAdvice
public class ZzhExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public SimpleResponse handler(Exception e) {
        if (e instanceof ZzhException) {
            ZzhException zzhException = (ZzhException) e;
            return new SimpleResponse(false, zzhException.getMsg());

        }else {
            return SimpleResponse.fail("全局异常,未知错误");
        }
    }

}
